package com.abel.demo.utils;

import java.util.Collection;
import java.util.List;

/**
 * Author: Abel.lin
 * Date: Created in 2018/7/13 14:55
 * Company: Abel.Studio
 * Copyright: Copyright (c) 2017
 * Description:
 */
public class BaseUtil {
    /**
     * @author: Abel.lin
     * @date: 2018/7/13 15:00
     * @description: 字符串是否为空
     * @return:
     */
    public static boolean isEmpty(String str){
        if(str == null || "".equals(str.trim())){
            return true;
        }
        return false;
    }
    /**
     * @author: Abel.lin
     * @date: 2018/7/13 15:01
     * @description: 集合是否为空
     * @return:
     */
    public static boolean isEmpty(Collection<?> list){
        if(list == null || list.size()==0){
            return true;
        }
        return false;
    }

    /**
     * @author: Abel.lin
     * @date: 2018/7/16 18:42
     * @description: 返回list第一个元素
     * @return:
     */
    public static <T> T firstIndex(List<T> list){
        if(list == null || list.size()==0){
            return null;
        }
        return list.get(0);
    }

    public static int strToInt(String str){
        try {
            return Integer.valueOf(str);
        }catch (NumberFormatException e){
            return 0;
        }
    }
    public static double strToDouble(String str){
        try {
            return Double.valueOf(str);
        }catch (NumberFormatException e){
            return 0.0;
        }
    }
}
